from app import db
from datetime import datetime

class Meal(db.Model):
    __tablename__ = 'meals'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    meal_type = db.Column(db.String(20), nullable=False)  # 早餐、午餐、晚餐、加餐
    food_name = db.Column(db.String(100), nullable=False)
    calories = db.Column(db.Integer)  # 卡路里
    protein = db.Column(db.Float)     # 蛋白质(克)
    fat = db.Column(db.Float)         # 脂肪(克)
    carbs = db.Column(db.Float)       # 碳水化合物(克)
    meal_date = db.Column(db.Date, nullable=False)
    meal_time = db.Column(db.Time, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    note = db.Column(db.String(200))
    
    user = db.relationship('User', backref=db.backref('meals', lazy='dynamic'))

    def __repr__(self):
        return f'<Meal {self.food_name} on {self.meal_date}>' 